<div class="form">
<?php $form = $this
	->beginWidget('CActiveForm',
		array(
			'id' => 'material-receipt-form',
			'enableAjaxValidation' => false,
		));
?>

	<p class="note">带 <span class="required">*</span> 的是必填的哦！</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model, 'projectId'); ?>
		<?php $this->widget('widgets.project.JProjectSelector',
				array(
					'model' => $model,
					'attribute' => 'projectId',
				));
		?>
		<?php echo $form->error($model, 'projectId'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'receiptDate'); ?>
		<?php $this
			->widget('zii.widgets.jui.CJuiDatePicker',
				array(
					'model' => $model,
					'attribute' => 'receiptDate',
				));
		?>
		<?php echo $form->error($model, 'receiptDate'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'token'); ?>
		<?php echo $form
			->textField($model, 'token', array(
				'size' => 60,
				'maxlength' => 255,
				'onBlur'=>'if(this.value){jQuery("#token-preload-check").load('.CJSON::encode( $this->createUrl('checkExistToken',array('token'=>'__token__','currentId'=>$model->isNewRecord?'':$model->id))).'.replace("__token__",this.value));}else{}'
			));
		?>
		<?php echo $form->error($model, 'note'); ?>
		<div class="clear"></div>
		<div id="token-preload-check" class="prepend-3">票据检查：等待输入中.........</div>
		</div>
	<div class="row">
		<?php echo $form->labelEx($model, 'merchantId'); ?>
<?php
if ($model->getIsNewRecord()) {
	$checkMerchantUrl = $this
		->createUrl('checkMerchant', array(
			'merchantId' => '__merchantId__'
		));
	$checkMerchantUrl = CJSON::encode($checkMerchantUrl);
	$this
		->widget('widgets.merchant.JMerchantSelector',
			array(
				'model' => $model,
				'attribute' => 'merchantId',
				'relatedAttribute' => 'merchant',
				'onSelectCallback' => <<<EOF
function(merchantId){
jQuery('#material-receipt-check-merchant').html('正在查找历史记录.....');
	var loadUrl=$checkMerchantUrl.replace('__merchantId__',merchantId);
	jQuery('#material-receipt-check-merchant').load(loadUrl);
}
EOF
			));
	echo $form->error($model, 'merchantId');
?>
	<div id="material-receipt-check-merchant" class="span-18 prepend-3" style="margin-bottom: 10px;">
	</div>
	<?php
	} else {
		$this
			->widget('widgets.merchant.JMerchantSelector',
				array(
					'model' => $model,
					'attribute' => 'merchantId',
					'relatedAttribute' => 'merchant'
				));
		echo $form->error($model, 'merchantId');
	}
	?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'handler'); ?>
		<?php echo $form
			->textField($model, 'handler', array(
				'size' => 10,
				'maxlength' => 255
			));
		?>
		<?php echo $form->error($model, 'handler'); ?>
	
<?php
$handlers = MaterialReceipt::getPopularHandlers();
foreach ($handlers as $handler) {
?><a class="material-receipt-handler-popular" href="#"><?php echo $handler; ?></a>
	<?php
	}
	$handlerFieldId = CHtml::activeId($model, 'handler');
	$script = <<<EOF
	jQuery('.material-receipt-handler-popular').click(function(){
	jQuery('#$handlerFieldId').val(jQuery(this).html());
	return false;
});
EOF
	;
	Yii::app()->clientScript->registerScript('material-receipt-handler-popular', $script);
	?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model, 'note'); ?>
		<?php echo $form
			->textField($model, 'note', array(
				'size' => 60,
				'maxlength' => 255
			));
		?>
		<?php echo $form->error($model, 'note'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'type'); ?>
		<?php echo $form
			->dropDownList($model, 'type', MaterialReceipt::getTypes(),
				array(
					'empty' => ''
				));
		?>
		<?php echo $form->error($model, 'type'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'processingCost'); ?>
		<?php echo $form
			->textField($model, 'processingCost',
				array(
					'size' => 16,
					'maxlength' => 16
				));
		?>
		<?php echo $form->error($model, 'processingCost'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'transportationCost'); ?>
		<?php echo $form
			->textField($model, 'transportationCost',
				array(
					'size' => 16,
					'maxlength' => 16
				));
		?>
		<?php echo $form->error($model, 'transportationCost'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'discount'); ?>
		<?php echo $form
			->textField($model, 'discount', array(
				'size' => 16,
				'maxlength' => 16
			));
		?>
		<?php echo $form->error($model, 'discount'); ?>
		<span class="hint">折扣请用负数</span>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'otherCost'); ?>
		<?php echo $form
			->textField($model, 'otherCost', array(
				'size' => 16,
				'maxlength' => 16
			));
		?>
		<?php echo $form->error($model, 'otherCost'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model, 'warehouseManagerId'); ?>
		<?php $this->widget('widgets.employee.JEmployeeSelector',array(
				'model'=>$model,
				'attribute'=> 'warehouseManagerId',
				'tag'=>'MATERIAL_WAREHOUSE_MANAGER',
				'linkProjectSelectorId'=>CHtml::activeId($model, 'projectId')
			));
		?>
		<?php echo $form->error($model, 'warehouseManagerId'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model, 'priceCheckable'); ?>
		<?php echo $form->checkBox($model, 'priceCheckable'); ?>
		<?php echo $form->error($model, 'priceCheckable'); ?>
	</div>

	<?php if (!AccessControl::isAltMode()) { ?>
	<div class="row">
		<?php echo $form->labelEx($model, 'altMode'); ?>
		<?php echo $form->checkBox($model, 'altMode'); ?>
		<?php echo $form->error($model, 'altMode'); ?>
	</div>
	<?php } ?>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? '新建' : '保存'); ?>
	</div>
<?php $this->endWidget(); ?>

</div><!-- form -->
